<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
// This tests the anchorNode, anchorOffset, focusNode and focusOffset properties
// of the Selection object.  These properties are part of Mozilla's Selection
// object API, and so their values should be consistent in both browsers.

selection_test(
  '<div id="test" style="border: 1px solid blue;">text</div>',
  selection => {
    assert_not_equals(
        window.eventSender, undefined,
        'This test requires window.eventSender to simulate mouse clicks');

    const document = selection.document;
    const elem = document.getElementById('test');

    // (x1, y) to (x2, y) should select the element.
    // selects the text from right to left.
    const x1 = selection.computeLeft(elem) + elem.offsetWidth;
    const x2 = selection.computeLeft(elem);
    const y = selection.computeTop(elem) + elem.offsetHeight / 2;

    eventSender.mouseMoveTo(x1, y);
    eventSender.mouseDown();
    eventSender.mouseMoveTo(x1, y);
    eventSender.mouseMoveTo(x2, y);
    eventSender.mouseUp();
  },
  '<div id="test" style="border: 1px solid blue;">|text^</div>',
  'Anchor and focus of selection set by backwards mouse dragging');
</script>
